#ifndef __STATUS_H
#define __STATUS_H

#ifdef __LPC17XX__
#include <stdio.h>
#include <stdlib.h>
#include "lpc17xx.h"

#define STATUS_UPDATE_TO_COMPUTER(x) status_update_to_computer((uint8_t *)&x, (uint16_t)((uint32_t)&x - (uint32_t)&status), sizeof(x))

#endif

#ifndef __LPC17XX__
  #define int8_t  qint8
  #define int16_t qint16
  #define int32_t qint32
  #define int64_t qint64
#endif

//! Bit is set if VFO A has got TX focus
#define STATUS_VFO_TXRX_VFOA_TX   0
//! Bit is set if VFO A has got RX focus
#define STATUS_VFO_TXRX_VFOA_RX   1
//! Bit is set if VFO B has got TX focus
#define STATUS_VFO_TXRX_VFOB_TX   2
//! Bit is set if VFO B has got RX focus
#define STATUS_VFO_TXRX_VFOB_RX   3

//! Bit which shows PTT input via the Footswitch
#define STATUS_PTT_INPUT_FOOTSWITCH    0
//! Bit which shows PTT input via the Winkey ports RTS
#define STATUS_PTT_INPUT_WK_RTS        1
//! Bit which shows PTT input via the Winkey ports DTR
#define STATUS_PTT_INPUT_WK_DTR        2
//! Bit which shows PTT input via the FSK/CW port RTS
#define STATUS_PTT_INPUT_FSKCW_RTS     3
//! Bit which shows PTT input via VOX sense input
#define STATUS_PTT_INPUT_VOX_SENSE     4

typedef struct __attribute__ ((aligned(1))) {
  //! VFO A frequency in Hz
  uint32_t vfoA_freq;
  //! VFO B frequency in Hz
  uint32_t vfoB_freq;
  //! The TX/RX state of the VFOs, see defines above
  uint8_t vfoAB_tx_rx_state;
} struct_radio_status;

typedef struct __attribute__ ((aligned(1))) {
  uint8_t ptt_input_state;
  uint8_t ptt_output_state;
} struct_ptt_status;

typedef struct __attribute__ ((aligned(1))) {
  struct_radio_status radio_status;
  struct_ptt_status ptt_status;
} struct_status;

#ifdef __LPC17XX__

void status_update_to_computer(uint8_t *data, uint16_t offset, uint8_t length);
void status_update_from_computer(uint8_t *data, uint16_t offset, uint8_t length);
void status_execute_update(void);

void status_set_vfoA_freq(uint32_t freq);
void status_set_vfoB_freq(uint32_t freq);
void status_set_vfoAB_txrx_state(uint8_t state);
uint32_t status_get_vfoA_freq(void);
uint32_t status_get_vfoB_freq(void);
uint8_t status_get_vfoAB_txrx_state(void);

void status_set_ptt_input_state_clr(uint8_t bit_nr);
void status_set_ptt_input_state_set(uint8_t bit_nr);
void status_set_ptt_input_state(uint8_t state);
uint8_t status_get_ptt_input_state(uint8_t bit_nr);

#endif

#endif /* end __STATUS_STRUCTS_H */
/****************************************************************************
** End Of File
*****************************************************************************/
